package com.zhilianbao.leyaogo.ui.adapter.home.grids;

import android.app.Activity;
import android.content.Context;

import com.bql.baseadapter.recycleView.QuickRcvAdapter;
import com.bql.baseadapter.recycleView.QuickRcvHolder;
import com.zhilianbao.leyaogo.R;
import com.zhilianbao.leyaogo.ui.activity.me.moneyaccount.BalanceActivity;
import com.zhilianbao.leyaogo.utils.ImageUtils;
import com.zhilianbao.leyaogo.utils.LogicCodeBlock;
import com.zhilianbao.leyaogo.utils.Utils;

import java.util.List;

/**
 * ClassName: HomeColumnAdapter <br>
 * Description: 首页栏目广告Adapter<br>
 * Author: Cyarie <br>
 * Created: 2016/12/14 16:40 <br>
 * Update Time：<br>
 * Update Description：<br>
 */
public class HomeAppGirdsAdapter extends QuickRcvAdapter<HomeAppGrids.HomeAppGridsData.HomeAppGridsBean> {

    public HomeAppGirdsAdapter(Context context, List<HomeAppGrids.HomeAppGridsData.HomeAppGridsBean> data) {
        super(context, data, R.layout.item_home_column);
    }

    @Override
    protected void bindDataHelper(QuickRcvHolder viewHolder, int position, HomeAppGrids.HomeAppGridsData.HomeAppGridsBean item) {
        ImageUtils.loadGoodsPic(Utils.returnUrlShow(item.getImg()), viewHolder.getView(R.id.iv_column_icon));
        viewHolder.setText(R.id.tv_column_title, item.getName());
        viewHolder.getView(R.id.rl_item).setOnClickListener(v -> {
            switch (item.getType()) {
                //跳转到商品详情
                case 0:
                    Utils.startGoodsDetails((Activity) mContext, (int) item.getId(), (int)item.getGoodsSkuId(), false);
                    break;
                //跳转到商品列表
                case 1:
                    Utils.startGoodsClassifyList((Activity) mContext, item.getId(), item.getTitle());
                    break;
                //跳转到专题活动详情
                case 2:
                case 3:
                    Utils.startActivityDetails((Activity) mContext, item.getId(), false);
                    break;

                //充值有礼
                case 4:
                    if (Utils.isUserLogin(true, LogicCodeBlock.LogicState.Recharge.value)) {
                        Utils.startActivity((Activity) mContext, BalanceActivity.class);
                    } else {
                        LogicCodeBlock.create().registerLogicCodeCallback(logicState -> {
                                    if (logicState == LogicCodeBlock.LogicState.Recharge.value)
                                        Utils.startActivity((Activity) mContext, BalanceActivity.class);
                                }
                        );
                    }

                    break;
            }
        });
    }
}
